package com.ruoyi.crm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.BaseSpaceLocation;
import com.ruoyi.crm.service.IBaseSpaceLocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 空间位置Controller
 *
 * @author ruoyi
 * @date 2023-04-10
 */
@RestController
@RequestMapping("/crm/location")
public class BaseSpaceLocationController extends BaseController
{
    @Autowired
    private IBaseSpaceLocationService baseSpaceLocationService;

    /**
     * 查询空间位置列表
     */
    @PreAuthorize("@ss.hasPermi('crm:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseSpaceLocation baseSpaceLocation)
    {
        startPage();
        List<BaseSpaceLocation> list = baseSpaceLocationService.selectBaseSpaceLocationList(baseSpaceLocation);
        return getDataTable(list);
    }

    /**
     * 导出空间位置列表
     */
    @PreAuthorize("@ss.hasPermi('crm:location:export')")
    @Log(title = "空间位置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseSpaceLocation baseSpaceLocation)
    {
        List<BaseSpaceLocation> list = baseSpaceLocationService.selectBaseSpaceLocationList(baseSpaceLocation);
        ExcelUtil<BaseSpaceLocation> util = new ExcelUtil<BaseSpaceLocation>(BaseSpaceLocation.class);
        util.exportExcel(response, list, "空间位置数据");
    }

    /**
     * 获取空间位置详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:location:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseSpaceLocationService.selectBaseSpaceLocationById(id));
    }

    /**
     * 新增空间位置
     */
    @PreAuthorize("@ss.hasPermi('crm:location:add')")
    @Log(title = "空间位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseSpaceLocation baseSpaceLocation)
    {
        return toAjax(baseSpaceLocationService.insertBaseSpaceLocation(baseSpaceLocation));
    }

    /**
     * 修改空间位置
     */
    @PreAuthorize("@ss.hasPermi('crm:location:edit')")
    @Log(title = "空间位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseSpaceLocation baseSpaceLocation)
    {
        return toAjax(baseSpaceLocationService.updateBaseSpaceLocation(baseSpaceLocation));
    }

    /**
     * 删除空间位置
     */
    @PreAuthorize("@ss.hasPermi('crm:location:remove')")
    @Log(title = "空间位置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseSpaceLocationService.deleteBaseSpaceLocationByIds(ids));
    }
}
